import {asyncRouterMap, constantRouterMap} from 'src/router';


const permission = {
  state: {
    routers: constantRouterMap,
    subRouters: [],
    addRouters: []
  },
  mutations: {
    SET_SUBROUTERS: (state, path) => {
      if (path == '/') {
        for (let idx in state.routers) {
          if (state.routers[idx].children && !state.routers[idx].hidden) {
            state.subRouters = state.routers[idx].children;
            break;
          }
        }
      } else {
        let subR = state.routers.find((route) => {
          return route.path == path;
        });
        if (subR)
          state.subRouters = subR.children;
      }

    },
  },
  actions: {
    GenerateRoutes({commit}, data) {
      const {user} = data;
      console.log('--------------', data);
      return new Promise(resolve => {
        //commit('SET_ROUTERS', filterAsyncRouter(asyncRouterMap, user.menus));
        resolve();
      })
    }
  }
};

export default permission;
